<template>
  <div class="app-container">
    <div class="content">
      <div class="rightHeader">
        <div class="header">
          <div class="logoBox">
            <img src="@/assets/images/logo.png" alt="" />
          </div>
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="large"
            :inline="true"
            :rules="formRules"
          >
            <el-form-item label="日期:" prop="lastUpdateDate">
              <el-date-picker
                v-model="queryParams.lastUpdateDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                :picker-options="setDisabled"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="medium"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button
                type="primary"
                icon="el-icon-refresh"
                size="medium"
                @click="resetQuery"
                >重置</el-button
              >
              <el-button
                type="primary"
                plain
                icon="el-icon-refresh-left"
                size="medium"
                :disabled="multiple"
                @click="handleAll"
                >批量回传</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <div class="footer">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
          <span @click="goBack">退出</span>
        </div>
      </div>
      <div class="wtable">
        <el-tabs
          v-model="activeName"
          @tab-click="handleClick"
          class="tableContent"
        >
          <el-tab-pane label="电子标签失败推送" name="first">
            <div>
              <!-- <el-row>
                <el-col>
                  <el-button
                    class="wmsbutton"
                    type="danger"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleAll"
                    >批量回传</el-button
                  >
                </el-col>
              </el-row> -->
              <el-table
                ref="tableData"
                :data="tableData"
                @selection-change="handleSelectionChange"
                @select-all="handleSelectionAllChange"
                class="tableContent1"
                height="720"
                v-loading="loading"
                element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.8)"
              >
                <el-table-column
                  :selectable="checkboxState"
                  type="selection"
                  width="55"
                  align="center"
                />
                <el-table-column
                  fixed
                  prop="pickOrder"
                  label="订单号"
                  width="180"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  fixed
                  prop="boxNo"
                  label="周转箱号"
                  width="180"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="locator"
                  label="库位"
                  width="180"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="wmsId"
                  label="唯一订单行"
                  width="180"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="requireQuantity"
                  label="需求数量"
                  width="180"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="actualQuantity"
                  label="拣货数量"
                  width="120"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="pickUser"
                  label="拣货人"
                  width="120"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="lastUpdateDate"
                  label="拣货时间"
                  width="160"
                  align="center"
                >
                </el-table-column>
                <el-table-column label="回传状态" width="200" align="center">
                  <template slot-scope="scope">
                    <span v-if="scope.row.flag == '0'">未拣货</span>
                    <span v-if="scope.row.flag == '1'">拣选未回传</span>
                    <span v-if="scope.row.flag == '2'">回传成功</span>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="failCount"
                  label="回传次数"
                  width="150"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-refresh-left"
                      @click="handleUpdate(scope.row)"
                      >回传</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="播种任务绑定" name="second"
            >开发中...</el-tab-pane
          >
          <el-tab-pane label="播种完成" name="third">开发中...</el-tab-pane>
          <el-tab-pane label="播种复核完成" name="fourth"
            >开发中...</el-tab-pane
          >
        </el-tabs>
        <div>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="handleQuery"
          />
        </div>
      </div>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      @close="dialogVisible = false"
    >
      <span>未查询到数据</span>
    </el-dialog>
  </div>
</template>

<script>
import { getElectrotag, getUpStatus } from "@/api/subSystem/continer";
export default {
  data() {
    return {
      setDisabled: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      activeName: "first",
      // 弹窗隐藏
      dialogVisible: false,
      // 总条数
      total: 0,
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        //年月日
        lastUpdateDate: new Date().toISOString().split("T")[0],
      },
      initialTableData: [], // 初始状态的表格数据
      tableData: [],
      formRules: {
        lastUpdateDate: [
          { required: true, message: "请输入查询日期", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    // canSelect(row, index) {
    //   if (index===4) {
    //     return false;
    //   } else {
    //     return true;
    //   }
    // },
    // customSelectable(row, index) {

    // },
    checkboxState() {
      return false;
    },
    handleSelectionAllChange(selection) {
      // console.log(selection);
      const flag = selection.length;
      console.log("flag", flag);
      this.tableData.forEach((data) => {
        this.$refs.tableData.toggleRowSelection(data, !flag);
      });
    },
    handleAll() {
      const formData = new FormData();
      formData.append("lastUpdateDate", this.queryParams.lastUpdateDate);
      formData.append("wmsId", "all");
      // const params = {
      //   lastUpdateDate:this.queryParams.lastUpdateDate,
      //   wmsId:"all"
      // }
      this.$modal
        .confirm("是否确认批量回传这些数据项？")
        .then(() => {
          // 用户点击了确认按钮，执行以下代码
          getUpStatus(formData).then((res) => {
            // getUpStatus(params).then((res) => {
            console.log(res);
            if (res.code == 200) {
              const msgdata = res.data.message;
              this.$message.success(msgdata);
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消批量回传");
        });
      //   getUpStatus(formData).then((res) => {
      //     console.log(res);
      //   });
    },
    handleUpdate(row) {
      const wmsId = row.wmsId || this.ids;
      const formData = new FormData();
      formData.append("lastUpdateDate", this.queryParams.lastUpdateDate);
      formData.append("wmsId", wmsId);
      this.$modal
        .confirm('是否确认回传唯一订单行为"' + wmsId + '"的数据项？')
        .then(() => {
          // 用户点击了确认按钮，执行以下代码
          getUpStatus(formData).then((res) => {
            console.log(res);
            if (res.code == 200) {
              const msgdata = res.data.message;
              const msgsdata = res.data.data;
              this.$message.success(msgdata + "," + msgsdata);
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消回传");
        });
      //    getUpStatus(formData).then((res) => {
      //     console.log(res);
      //   });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.wmsId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    resetQuery() {
      this.tableData = [...this.initialTableData];
    },
    goBack() {
      this.$router.push("/subSystem1");
    },
    handleQuery() {
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          getElectrotag(this.queryParams).then((res) => {
            if (Array.isArray(res.rows) && res.rows.length > 0) {
              this.tableData = res.rows;
              this.total = res.total;
              this.loading = false;
            } else {
              this.tableData = res.rows;
              this.total = res.total;
              this.dialogVisible = true;
              this.loading = false;
            }
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 0 !important;
  width: 100%;
  height: 100%;
  background: url("../assets/images/hcbanner2.jpg") no-repeat;
  overflow: hidden;
  ::v-deep .el-form-item__label {
    color: #fff;
    font-size: 18px;
    font-weight: 400;
  }
  ::v-deep .el-table__empty-block {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }
  ::v-deep .el-pagination__jump {
    color: #ffffff;
  }
  ::v-deep .el-pagination__total {
    color: #ffffff;
  }
  ::v-deep .el-pagination {
    margin-right: 78px;
  }
  .pagination-container {
    background: transparent;
    margin-top: 5px !important;
    padding: 0px 20px !important;
  }
  .content {
    height: 100%;
  }
  .rightHeader {
    height: 50px;
    margin-top: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .header {
      display: flex;
      justify-content: flex-start;
      margin-left: 30px;
      .logoBox {
        width: 200px;
        margin-right: 450px;
        margin-top: -60px;
        margin-left: -20px;
        img {
          width: 200%;
        }
      }
    }
    .footer {
      display: flex;
      align-items: center;
      cursor: pointer;
      margin-top: -50px;
      color: #ffffff5d;
      font-size: 18px;
      img {
        width: 30%;
      }
      span {
        display: block;
        margin-left: -40px;
        margin-top: 15px;
        font-size: 12px;
      }
    }
  }
  .wtable {
    width: 100%;
    text-align: center;
  }
  .tableContent {
    margin: 0 auto;
    width: 95%;
    margin-top: -30px;
  }
  .tableContent1 {
    margin: 0 auto;
    width: 100%;
    margin-top: 10px;
  }
  .el-button--medium {
    padding: 10px 20px;
    font-size: 16px;
  }
  ::v-deep .el-form-item__label {
    color: #fff;
  }
  ::v-deep .el-input {
    width: 100%;
    font-size: 16px;
  }
  ::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
  }
  ::v-deep .el-pagination.is-background .btn-next:disabled {
    color: #797a7b;
  }
  ::v-deep .el-pagination.is-background .btn-prev:disabled {
    color: #797a7b;
  }
  ::v-deep .el-pagination span:not([class*="suffix"]) {
    min-width: 56.5px;
  }
  ::v-deep .el-tabs__header {
    padding: 0;
    position: relative;
    margin: 30px 100px 20px 100px;
    // width: 469px;
    // background-color: #f5f7fa00;
    // border-bottom: 1px solid #dfe4ed00;
  }
  ::v-deep .is-top {
    color: #fff;
  }
  ::v-deep .el-tabs__item:hover {
    color: #5baefc !important;
    cursor: pointer;
  }
  ::v-deep .el-tabs__item.is-active {
    color: #5baefc !important;
  }
}
</style>